/*
package com.lld.crowdfunding.service.impl;

import com.lld.crowdfunding.entity.QuanXian;
import com.lld.crowdfunding.entity.User;
import com.lld.crowdfunding.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
//@Service
public class UserDetailServiceImpl implements UserDetailsService {

    @Autowired
    UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {

        User user = userMapper.getAllUser(s, null).get(0);
        List<QuanXian> userQuanxian = userMapper.getUserQuanxian(user.getId());
        String str_quanxian = "";
        for(QuanXian quanXian:userQuanxian) {
            str_quanxian = str_quanxian+","+quanXian.getQxUrl();
        }
        if(user == null) {
            throw new UsernameNotFoundException("用户名不存在");
        }

        List<GrantedAuthority> auths = AuthorityUtils.commaSeparatedStringToAuthorityList(str_quanxian);

        return new org.springframework.security.core.userdetails.User(user.getLoginName(),
                new BCryptPasswordEncoder().encode(user.getUserPassword()),auths);
    }
}
*/
